package com.bit.cfdi.web.dao.impl;

import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bit.cfdi.web.dao.ConfiguracionCorreoDAO;
import com.bit.cfdi.web.domain.ConfiguracionCorreo;
import com.bit.cfdi.web.domain.Negocio;

@Repository
public class ConfiguracionCorreoDAOImpl extends HibernateDaoSupport implements
		ConfiguracionCorreoDAO {

	protected Logger log = LogManager.getLogger(this.getClass().getName());

	@Autowired
	public void init(final SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	
	@Override
	@Transactional public void save(ConfiguracionCorreo configuracionCorreo) throws DataAccessException{
		getHibernateTemplate().saveOrUpdate(configuracionCorreo);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public List<ConfiguracionCorreo> getConfiguracionCorreo(Negocio negocio) throws DataAccessException{
		List<ConfiguracionCorreo> toReturn = getHibernateTemplate().find(
				" from ConfiguracionCorreo as cc" +
				" where cc.negocio=?", negocio);
		return toReturn;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public List<ConfiguracionCorreo> getAll() throws DataAccessException {
		List<ConfiguracionCorreo> toReturn = getHibernateTemplate().find(
				" from ConfiguracionCorreo as cc");
		return toReturn;
	}

}